# -*- coding: utf-8 -*-
# author:HHR
# time:2021/2/21:8:50
# ___msg___ = '创建年费任务'

from Db_connect import DB_connect


class create_big_tasK():
    def __init__(self):
        self.mysql_con = DB_connect().online_db()
        self.mysql_cur = self.mysql_con.cursor()
        self.online_con = DB_connect().online_big_data()
        self.big_cur = self.online_con.cursor()
        self.redis_con = DB_connect().patents_reids()

    # def get_sqh(self):
    #     sql = "SELECT DISTINCT application_number FROM ccy_paid GROUP BY application_number"
    #     try:
    #         self.big_cur.execute(sql)
    #     except Exception as E:
    #         print("查询错误！", E)
    #     all_data_1 = self.big_cur.fetchall()
    #     for item in all_data_1:
    #         self.redis_con.sadd("协和端口查询", item[0])

    def big_task(self):
        sql = "select distinct application_number from finals where application_number !='' and is_stop='0'"
        try:
            self.mysql_cur.execute(sql)
        except Exception as E:
            print("查询错误！", E)
        all_data = self.mysql_cur.fetchall()

        for one_data in all_data:
            select_sql = f"SELECT agency FROM xhhg_pantent_status where application_number = '{one_data[0]}'"
            self.big_cur.execute(select_sql)
            data = self.big_cur.fetchall()
            print(one_data)
            self.redis_con.sadd("专利状态查询", one_data[0])
            # if data:
            #     agency=data[0][0]
            # else:
            #     agency=''
            # import csv
            # with open('app_num.csv','a+',encoding='utf-8',newline='') as file:
            #     csv_writer= csv.writer(file)
            #     csv_writer.writerow([one_data[0],agency])
            # print(one_data[0], data)

            # try:
            #     agency = data[0][0]
            #     if agency:
            #         if "武汉信合红谷知识产权代理事务所" in data[0][0]:
            #             print("信合红谷接口查询", one_data[0])
            #             self.redis_con.sadd("信合红谷接口查询", one_data[0])
            #         else:
            #             print("外部接口查询", one_data[0])
            #             self.redis_con.sadd("外部接口接口查询", one_data[0])
            #     else:
            #         print("协和端口查询", one_data[0])
            #         self.redis_con.sadd("协和端口查询", one_data[0])
            # except:
            #     print("外部接口查询", one_data[0])
            #     self.redis_con.sadd("协和端口查询", one_data[0])


    def main(self):
        self.big_task()
        # self.get_sqh()
        self.mysql_cur.close()
        self.mysql_con.close()
        self.big_cur.close()
        self.online_con.close()


if __name__ == '__main__':
    create_big_tasK().main()
